package com.woniu.product.controller;


import com.woniu.entity.Result;
import com.woniu.product.pojo.ProductComment;
import com.woniu.product.entity.dto.ReplyDTO;
import com.woniu.product.pojo.vo.ProductCommentVo;
import com.woniu.product.service.IProductCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品评价表 前端控制器
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
@Api(tags = "商品评价管理")
@RestController
@RequestMapping("/product-comment")
public class ProductCommentController {

    @Autowired
    private IProductCommentService productCommentService;


    @ApiOperation("根据商品id查询所有评论")
    @GetMapping("/{id}")
    public Result listAllComment(@PathVariable String id){
        List<ProductComment> productCommentList = productCommentService.listAllComment(id);
        return Result.ok(productCommentList);
    }

    @ApiOperation("查询所有的评论回复")
    @GetMapping("/comment")
    public Result<List<ProductCommentVo>> listAllTree(){
        List<ProductCommentVo> productCommentVoList = productCommentService.listAllTree();
        return Result.ok(productCommentVoList);
    }

    @ApiOperation("回复评论")
    @PutMapping("/reply")
    public Result queryReply(@RequestBody ReplyDTO replyDTO){
        productCommentService.saveReply(replyDTO);
        return Result.ok();
    }
}
